
import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.m3g.Graphics3D;

public class ExitScreen extends GameCanvas implements Runnable {

    private int WIDTH = 240;
    private int HEIGH = 320;
    private Image backImg;
    private int delay;
    private int alphaVal;
    private boolean running;
    private Main iMain;

    public ExitScreen(Main aMain) {
        super(true);
        setFullScreenMode(true);
        delay = 40;
        alphaVal = 255;
        running = true;
        iMain = aMain;
        
        try {
            backImg = Image.createImage("Pikachu_Menu.png");
        } catch (IOException ioexception) {
        }
        Thread thread = new Thread(this);
        thread.start();
    }

    public void run() {
        while (running) {
            if (alphaVal > 0) {
                alphaVal -= 5;
            }
            if (alphaVal <= 0) {
                alphaVal = 0;
                running = false;
            }
            repaint();
            try {
                Thread.sleep(delay);
            } catch (InterruptedException interruptedexception) {
            }
        }
        iMain.exit();
    }

    public void paint(Graphics g) {        
        g.setColor(255, 255, 255);
        g.fillRect(0, 0, backImg.getWidth(), backImg.getHeight());
        
        int ai[] = new int[backImg.getWidth() * backImg.getHeight()];
        backImg.getRGB(ai, 0, backImg.getWidth(), 0, 0, backImg.getWidth(), backImg.getHeight());
        ImageEffect.blend(ai, alphaVal);
        Image image = Image.createRGBImage(ai, backImg.getWidth(), backImg.getHeight(), true);
        g.drawImage(image, 0, 0, 20);
        
        g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE));
        g.setColor(0, 0, 0);
        g.drawString("Goodbye!", 120, 150, Graphics.TOP|Graphics.HCENTER);
    }

    public void keyPressed(int i) {
        iMain.exit();
    }
}
